package com.sky.controller.admin;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 查询订单信息
     * @param id
     * @return
     */
    @ApiOperation("查询订单信息")
    @GetMapping("/details/{id}")
    public Result query(@PathVariable Long id){
        OrderVO orderVO = orderService.findByOrderId(id);
        return Result.success(orderVO);
    }


    /**
     * 条件分页查询订单
     * @param pageQueryDTO
     * @return
     */
    @ApiOperation("条件分页查询订单")
    @GetMapping("/conditionSearch")
    public Result pageQuery(OrdersPageQueryDTO pageQueryDTO){
        PageResult pageResult = orderService.pagequery(pageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各订单状态数量统计
     * @return
     */
    @ApiOperation("各订单状态数量统计")
    @GetMapping("/statistics")
    public Result statistic(){
        OrderStatisticsVO statisticsVO = orderService.statistic();
        return Result.success(statisticsVO);
    }

    /**
     * 接单
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersDTO ordersDTO){
        orderService.confirm(ordersDTO);
        return Result.success();
    }

    /**
     * 拒单
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody Orders orders){
        orderService.reject(orders);
        return Result.success();
    }

    /**
     * 取消订单
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody Orders orders){
        //实现逻辑和拒单一摸一样
        orderService.reject(orders);
        return Result.success();
    }

    /**
     * 派送
     */
    @ApiOperation("派送")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成
     */
    @ApiOperation("完成")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }




}
